package cn.tedu.file;

import java.io.*;
import java.util.Scanner;

/**
 * @author :Colin
 * @version 创建时间: 2021/6/17 20:28
 */
public class TestCopyFile2 {
    public static void main(String[] args) {
        System.out.println("文件路径");
        String f=new Scanner(System.in).nextLine();
        System.out.println("目标路径");
        String t=new Scanner(System.in).nextLine();
        method(f,t);


    }

    private static void method(String f,String t) {
        InputStream in=null;
        OutputStream out=null;
        try{
            in = new BufferedInputStream(new FileInputStream(f));
            out= new BufferedOutputStream(new FileOutputStream(t));
            int b;
            while((b=in.read())!=-1){
                out.write(b);
            }
            System.out.println("文件复制成功");
        }catch(Exception e){
            System.out.println("输入错误");
            e.printStackTrace();
        }finally{
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
